package dashboard.constant;

import java.util.HashMap;


/**
 * 数据来源枚举
 * @author zhaoxiang 2015-1-26
 * @since 1.0
 */
public enum EnumSource {
	total;

	public String getDBName() {
		switch (this) {
		case total:
			return "all";
		default:
			return "all";
		}
	}

	private static final String SOURCE_TWO = "business_name='%s' AND page_type='%s' AND platform='%s' and source1_name='%s' and source2!='all' GROUP BY %s";
	private static final String SOURCE_TWO_VPPV_UV = "business_name='%s' AND platform='%s' AND (page_type='all' OR page_type='detail') and source1_name='%s' and source2!='all'  GROUP BY %s";

	
	/**
	 * 获取流量二级来源“趋势图”查询条件
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-1-29
	 */
	public static String getSourceTwoCon(NetFlowIndex index,EnumCate cate,EnumPlatform platEnum,String source1,String groupBy) {
		switch (index) {
			case vppv:
				return String.format(SOURCE_TWO,cate.getDBName(), EnumPageType.detail.getDBName(),platEnum.getColName(),source1, groupBy);
			case vppvDIVuv:// 既需要详情页算vppv 又需要所有算uv
				return String.format(SOURCE_TWO_VPPV_UV, cate.getDBName(),platEnum.getColName(),source1, groupBy);
			case lide_pv:
				return String.format(SOURCE_TWO, cate.getDBName(), EnumPageType.listanddetail.getDBName(),platEnum.getColName(),source1, groupBy);
			case lide_uv:
				return String.format(SOURCE_TWO, cate.getDBName(), EnumPageType.listanddetail.getDBName(),platEnum.getColName(),source1, groupBy);
			default:// pv uv pvDIVuv 只需要所有
				return String.format(SOURCE_TWO, cate.getDBName(), "all",platEnum.getColName(),source1, groupBy);
		}
	}	

	private static final String SOURCE_THREE = "business_name='%s' AND page_type='%s' AND platform='%s' and source2_name='%s' and source3!='all' GROUP BY %s";
	private static final String SOURCE_THREE_VPPV_UV = "business_name='%s' AND platform='%s' AND (page_type='all' OR page_type='detail') and source2_name='%s' and source3!='all'  GROUP BY %s";

	
	/**
	 * 获取流量三级来源“趋势图”查询条件
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-1-29
	 */
	public static String getSourceThreeCon(NetFlowIndex index,EnumCate cate,EnumPlatform platEnum,String source2,String groupBy) {
		switch (index) {
			case vppv:
				return String.format(SOURCE_THREE, cate.getDBName(), EnumPageType.detail.getDBName(),platEnum.getColName(),source2, groupBy);
			case vppvDIVuv:// 既需要详情页算vppv 又需要所有算uv
				return String.format(SOURCE_THREE_VPPV_UV, cate.getDBName(),platEnum.getColName(),source2, groupBy);
			case lide_pv:
				return String.format(SOURCE_THREE, cate.getDBName(), EnumPageType.listanddetail.getDBName(),platEnum.getColName(),source2, groupBy);
			case lide_uv:
				return String.format(SOURCE_THREE, cate.getDBName(), EnumPageType.listanddetail.getDBName(),platEnum.getColName(),source2, groupBy);
			default:// pv uv pvDIVuv 只需要所有
				return String.format(SOURCE_THREE, cate.getDBName(), "all",platEnum.getColName(),source2, groupBy);
		}
	}	
	
	
	private static final String SOURCE_TWO_PIE = "stat_date >='%s' AND stat_date<='%s' AND business_name='%s' AND page_type='%s' AND platform='%s' and source1!='all' GROUP BY %s";
	private static final String SOURCE_TWO_PIE_VPPVdivUV = "stat_date >='%s' AND stat_date<='%s'  AND business_name='%s' AND platform='%s' AND (page_type='all' OR page_type='detail') and source1!='all'  GROUP BY %s";

	/**
	 * 获取流量二级来源 “饼图” 查询条件
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-1-29
	 */
	public static String getSourceTwoPieCon(NetFlowIndex index,EnumCate cate,EnumPlatform platEnum,String beginDate,String endDate,String groupBy) {
		switch (index) {
			case vppv:
				return String.format(SOURCE_TWO_PIE, beginDate, endDate,cate.getDBName(), EnumPageType.detail.getDBName(),platEnum.getColName(), groupBy);
			case vppvDIVuv:// 既需要详情页算vppv 又需要所有算uv
				return String.format(SOURCE_TWO_PIE_VPPVdivUV, beginDate, endDate, cate.getDBName(),platEnum.getColName(), groupBy);
			case lide_pv:
				return String.format(SOURCE_TWO_PIE, beginDate, endDate, cate.getDBName(), EnumPageType.listanddetail.getDBName(),platEnum.getColName(), groupBy);
			case lide_uv:
				return String.format(SOURCE_TWO_PIE, beginDate, endDate, cate.getDBName(), EnumPageType.listanddetail.getDBName(),platEnum.getColName(), groupBy);
			default:// pv uv pvDIVuv 只需要所有
				return String.format(SOURCE_TWO_PIE, beginDate, endDate, cate.getDBName(), EnumPageType.total.getDBName(),platEnum.getColName(), groupBy);
		}

	}	
	
	private static final HashMap<String, String> srouceMap = new HashMap<String, String>();
	
	static{
		srouceMap.put("source_pc", "'站内','站外免费','站外付费'");
		srouceMap.put("source1_pc", "'站内引荐','SEO','广告系列','站外引荐','直接访问','SEM'");
		srouceMap.put("source2_pc_SEO", "'百度','360搜索','有道','搜狗','其他'");
		srouceMap.put("source2_pc_广告系列", "'360导航','HAO123导航','搜狗导航','金山导航','2345导航','百度品牌专区','其他'");
		
		srouceMap.put("source_m", "'自有','SEO','渠道','手机QQ','陌陌','其他'");
		srouceMap.put("source1_m", "'自有','SEO','渠道','手机QQ','陌陌','其他'");
		srouceMap.put("source2_m_SEO", "'百度','360搜索','搜狗','百度应用','神马','其他'");
		srouceMap.put("source2_m_渠道", "'付费浏览器','联盟','付费其他','SEM'");
		
		srouceMap.put("source3_m_付费浏览器", "'UC浏览器','QQ浏览器','HAO123导航','百度搜索','360浏览器','小米浏览器','其他'");
		srouceMap.put("source3_m_联盟", "'QQ浏览器-招聘卡片','天盛丰翼','恩网','驾校一点通','其他'");
		srouceMap.put("source3_m_付费其他", "'百度品牌专区','百度轻应用','58APP分享','其他'");
	}
	
	public static String getSources(String key){
		return srouceMap.get(key);
	}
	
}
